package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.DzChewei;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzCwmx;
import com.ruoyi.system.service.IDzCwmxService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 车位明细Controller
 * 
 * @author ruoyi
 * @date 2023-09-15
 */
@RestController
@RequestMapping("/system/cwmx")
public class DzCwmxController extends BaseController
{
    @Autowired
    private IDzCwmxService dzCwmxService;

    /**
     * 查询车位明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzCwmx dzCwmx)
    {
        startPage();
        List<DzCwmx> list = dzCwmxService.selectDzCwmxList(dzCwmx);
        return getDataTable(list);
    }

    /**
     * 导出车位明细列表
     */
    @Log(title = "车位明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzCwmx dzCwmx)
    {
        List<DzCwmx> list = dzCwmxService.selectDzCwmxList(dzCwmx);
        ExcelUtil<DzCwmx> util = new ExcelUtil<DzCwmx>(DzCwmx.class);
        util.exportExcel(response, list, "车位明细数据");
    }

    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, Long cwId) throws Exception
    {
        ExcelUtil<DzCwmx> util = new ExcelUtil<DzCwmx>(DzCwmx.class);
        List<DzCwmx> list = util.importExcel(file.getInputStream());
        for(DzCwmx lpfy:list){
            lpfy.setCwId(cwId);
            dzCwmxService.insertDzCwmx(lpfy);
        }
        return AjaxResult.success("导入成功");
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<DzCwmx> util = new ExcelUtil<DzCwmx>(DzCwmx.class);
        util.importTemplateExcel(response, "数据");
    }

    /**
     * 获取车位明细详细信息
     */
    @GetMapping(value = "/{mxId}")
    public AjaxResult getInfo(@PathVariable("mxId") Long mxId)
    {
        return AjaxResult.success(dzCwmxService.selectDzCwmxByMxId(mxId));
    }

    /**
     * 新增车位明细
     */
    @Log(title = "车位明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzCwmx dzCwmx)
    {
        return toAjax(dzCwmxService.insertDzCwmx(dzCwmx));
    }

    /**
     * 修改车位明细
     */
    @Log(title = "车位明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzCwmx dzCwmx)
    {
        return toAjax(dzCwmxService.updateDzCwmx(dzCwmx));
    }

    /**
     * 删除车位明细
     */
    @Log(title = "车位明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mxIds}")
    public AjaxResult remove(@PathVariable Long[] mxIds)
    {
        return toAjax(dzCwmxService.deleteDzCwmxByMxIds(mxIds));
    }
}
